<?php
/**
 * 礼物模型
 * @return
 * @author yuncran@126.com
 */

namespace app\model;

use app\BaseModel;

class GiftModel extends BaseModel
{

    protected $name = 'gift';

    protected $pk = "id";


    public static function getGiftAll($user_id)
    {
        $param = app()->request->param();
        $data = self::getModel()->where('status',1)
            ->field(['id',field('title'),'status','create_time','describe','image','money','stock','sales'])
            ->when($param, function ($query) use ($param) {
            if (!empty($param['type'])) {
                $query->where('type', $param['type']);
            }
        })->paginate()->each(function ($item) {
            return $item;
        });
        return $data;
    }

    /**
     * 获取会员详情
     * @param $gift_id
     * @return void
     * @author yuncran@126.com
     *
     */
    public static function getDetails($gift_id)
    {
        $data = self::getModel()->where(['id'=>$gift_id])
            ->field(['id','type',field('title'),'describe','image','money','stock','sales',field('content'),'create_time']) ->find();
        return $data;
    }

}